package com.mdd.front.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.mdd.common.entity.notice.SystemNotice;
import com.mdd.common.mapper.notice.SystemNoticeMapper;
import com.mdd.front.service.INoticeService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
public class NoticeServiceImpl implements INoticeService {

    @Resource
    SystemNoticeMapper noticeMapper;

    @Override
    public List<SystemNotice> lists() {
        LambdaQueryWrapper<SystemNotice> query = new LambdaQueryWrapper<>();
        query.select(SystemNotice::getId,SystemNotice::getTitle,SystemNotice::getPublishTime);
        query.eq(SystemNotice::getStatus,0)
                        .eq(SystemNotice::getIsShow,0);
        query.lt(SystemNotice::getStartTime,new Date())
                .gt(SystemNotice::getEndTime,new Date());
        return noticeMapper.selectList(query);
    }

    @Override
    public SystemNotice detail(Integer id) {
        SystemNotice systemNotice = noticeMapper.selectById(id);
        SystemNotice notice = new SystemNotice();
        notice.setId(id);
        notice.setClick(systemNotice.getClick() + 1);
        noticeMapper.updateById(notice);
        return systemNotice;
    }
}
